﻿using System;
using System.Collections;
using System.Collections.Generic;
//using System.ComponentModel;
using System.Diagnostics;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

namespace DirectX_CS
{
	public partial class DirectXForm : Form, INamed
	{
		protected string shortName = "DXWindow";
		public string ShortName
		{
			get { return shortName; }
			set { shortName = value; }
		}
		private int shortNumber = 0;

		public int ShortNumber
		{
			get { return shortNumber; }
			set { shortNumber = value; }
		}
		[PGBrowsable]
		public string ObjectName
		{
			get { return shortName + " " + shortNumber; }
		}

		public Device Device
		{
			get { return MainProgram.DxDevice; }
		}
		private MainProgram mMainProgram = null;
		private PrimitiveManager mRenderer = null;
		private static DirectXForm onlyForm = null;

		public static DirectXForm OnlyForm
		{
			get { return DirectXForm.onlyForm; }
			set { DirectXForm.onlyForm = value; }
		}

		public PrimitiveManager RendererManager
		{
			get { return mRenderer; }
			set { mRenderer = value; }
		}
		ComboBoxEnumList cullModeList = null;
		ComboBoxEnumList shadeModeList = null;
		ComboBoxEnumList fillModeList = null;
        ComboBoxEnumList mSourceBlend = null;
        ComboBoxEnumList mDestinationBlend = null;
        ComboBoxEnumList mOperation = null;
	
		Vector3 cameraPosition = new Vector3(25, 25, 25);
		Vector3 cameraUpVector = new Vector3(0, 0, 1);
		Vector3 cameraTarget = new Vector3(0, 0, 0);

		Mouse currentMouse;

		public DirectXForm()
		{
			InitializeComponent();
			mMainProgram = MainProgram.OnlyProgram;

			this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
            this.DoubleBuffered = false;

            Rectangle screenRect = SystemInformation.VirtualScreen;
            this.Size = screenRect.Size;
            this.Location = screenRect.Location;
            this.WindowState = FormWindowState.Normal;

			
			//add handlers
			this.Resize += new EventHandler(mFrm_Resize);
			this.Paint += new PaintEventHandler(mFrm_Paint);

			this.FormClosing += new FormClosingEventHandler(frm_FormClosing);

			//this.MouseMove += new MouseEventHandler(currentMouse.mFrm_MouseMove);
			//this.MouseUp += new MouseEventHandler(currentMouse.mFrm_MouseUp);
			////add a form closed handler to the directx window host
			//this.MouseDown += new MouseEventHandler(currentMouse.mFrm_MouseDown);
			//this.MouseWheel += new MouseEventHandler(currentMouse.mFrm_MouseWheel);

			currentMouse = new Mouse(this);


			onlyForm = this;
		}

		void frm_FormClosing(object sender, FormClosingEventArgs e)
		{
			MainProgram.ExitProgram = true;
		}

				/// <summary>
		/// ////////////
		/// </summary>
		public void ShowNewObjectDropDown()
		{
			this.tsmiNewObject.ShowDropDown();
		}
		void mFrm_Paint(object sender, PaintEventArgs e)
		{
			//this.Invalidate();
			//mMainProgram.RenderScene();
			//this.Validate();
		}	
		void mFrm_Resize(object sender, EventArgs e)
		{
			this.Invalidate();
			mMainProgram.SetViewport();
			mMainProgram.SetupTransformProjection();
			//mMainProgram.RenderScene();
			this.Validate();
		}

		private void frmDirectX_Load(object sender, EventArgs e)
		{
			//Device.Transform.View = Matrix.LookAtLH(RelativeCameraPosition, CameraTarget, cameraUpVector); ;//

			cullModeList = new ComboBoxEnumList(typeof(Cull));			
			cullModeList.Fill(tscbCullMode, (int)Device.RenderState.CullMode);

			shadeModeList = new ComboBoxEnumList(typeof(ShadeMode));
			shadeModeList.Fill(tscbShadeMode, (int)Device.RenderState.ShadeMode);

			fillModeList = new ComboBoxEnumList(typeof(FillMode));
			fillModeList.Fill(tscbFillMode, (int)Device.RenderState.FillMode);

            mSourceBlend = new ComboBoxEnumList(typeof(Blend));
            mSourceBlend.Fill(tscbSourceBlend, (int)Device.RenderState.SourceBlend);

            mDestinationBlend = new ComboBoxEnumList(typeof(Blend));
            mSourceBlend.Fill(tscbDestinationBlend, (int)Device.RenderState.DestinationBlend);

            mOperation = new ComboBoxEnumList(typeof(BlendOperation));
            mOperation.Fill(tscbBlendOperation, (int)Device.RenderState.BlendOperation);

		}

		private void tsmiPrimitivesEditor_Click(object sender, EventArgs e)
		{
			ObjectsEditor f = mMainProgram.PrimitivesEditorForm;
			f.Show();
		}

		private void tsmiLightingEditor_Click(object sender, EventArgs e)
		{
			mMainProgram.LightingForm.Show();
		}

		private void tsmiNewCamera_Click(object sender, EventArgs e)
		{
			Camera newCamera = new Camera();
			newCamera.Text = "Camera " + Camera.CameraForms.Count;
			newCamera.Show(); 
		}

		private void tsmiRenderState_Click(object sender, EventArgs e)
		{
			tsmiZBuffer.Checked = Device.RenderState.ZBufferEnable;
			tsmiStencilEnable.Checked = Device.RenderState.StencilEnable;
			tstbPointSize.Text = Device.RenderState.PointSize.ToString();
		}

		private void tsmiZBuffer_Click(object sender, EventArgs e)
		{
			Device.RenderState.ZBufferEnable = !Device.RenderState.ZBufferEnable;
			//tsmiZBuffer.Checked = Device.RenderState.ZBufferEnable;
		}

		private void tscbCullMode_SelectedIndexChanged(object sender, EventArgs e)
		{
			 Device.RenderState.CullMode = (Cull)((SimpleComboBoxItem)tscbCullMode.SelectedItem).Value;
		}

		private void tscbShadeMode_SelectedIndexChanged(object sender, EventArgs e)
		{
			Device.RenderState.ShadeMode = (ShadeMode)((SimpleComboBoxItem)tscbShadeMode.SelectedItem).Value;
		}

		private void tsmiAlphaBlending_Enabled_Click(object sender, EventArgs e)
		{
			Device.RenderState.AlphaBlendEnable = tsmiAlphaBlending_Enabled.Checked;
		}

		private void tsmiMaterialEnabled_Click(object sender, EventArgs e)
		{
			mMainProgram.RendererManager.MaterialManagement = tsmiMaterialEnabled.Checked;
		}

		private void tscbFillMode_SelectedIndexChanged(object sender, EventArgs e)
		{
			Device.RenderState.FillMode = (FillMode)((SimpleComboBoxItem)tscbFillMode.SelectedItem).Value;
		}

		private void tsmiStencilEnable_Click(object sender, EventArgs e)
		{
			Device.RenderState.StencilEnable = tsmiStencilEnable.Checked;
		}

		private void tsmiOutputForm_Click(object sender, EventArgs e)
		{
			mMainProgram.OutputForm.ShowAFresh();
		}

		private void tstbPointSize_KeyDown(object sender, KeyEventArgs e)
		{
			const int ms = 5000;
			float max = Device.RenderState.PointSizeMax;
			float min = Device.RenderState.PointSizeMin;

			if (e.KeyCode == Keys.Enter)
			{
				float desiredPointSize;
				try
				{
					desiredPointSize = float.Parse(tstbPointSize.Text);

					if (desiredPointSize >= min && desiredPointSize <= max)
					{
						Device.RenderState.PointSize = desiredPointSize;							
					}
					else
					{
						mMainProgram.OutputForm.OutputThenGoAway("Invalid point size " + desiredPointSize + ". Point size must be between " + max.ToString() + " and " + min.ToString() + ".", ms);
					}
				}
				catch (Exception ex)
				{
					mMainProgram.OutputForm.OutputThenGoAway("Invalid point size. Point size must be between " + max.ToString() + " and " + min.ToString() + ".", ms);
				}
			}
		}

		private void tsmiFillMode_DropDownOpening(object sender, EventArgs e)
		{
			fillModeList.Select((int)Device.RenderState.FillMode);
		}

		private void tsmiShadeMode_DropDownOpening(object sender, EventArgs e)
		{
			shadeModeList.Select((int)Device.RenderState.ShadeMode);
		}

		private void tsmiCullMode_DropDownOpening(object sender, EventArgs e)
		{
			cullModeList.Select((int)Device.RenderState.CullMode);
		}

		private void tsmiAlphaBlending_DropDownOpening(object sender, EventArgs e)
		{
			tsmiAlphaBlending_Enabled.Checked = Device.RenderState.AlphaBlendEnable;
		}

		private void tsmiMaterial_DropDownOpening(object sender, EventArgs e)
		{
			tsmiMaterialEnabled.Checked = mMainProgram.RendererManager.MaterialManagement;

		}

		private void tsmiPointSize_DropDownOpening(object sender, EventArgs e)
		{
			tstbPointSize.Text = Device.RenderState.PointSize.ToString();
		}


		private void DirectXForm_Paint(object sender, PaintEventArgs e)
		{
			mnuMain.Refresh();
		}

        private void tsmiBlendFactor_Click(object sender, EventArgs e)
        {
            //
			cdBlendFactor.Color = Device.RenderState.BlendFactor; ;
        }

        private void tscbSourceBlend_SelectedIndexChanged(object sender, EventArgs e)
        {
            //Device.RenderState.FillMode = (FillMode)((ComboBoxItem)tscbFillMode.SelectedItem).Value;
            Device.RenderState.SourceBlend = (Blend)((SimpleComboBoxItem)tscbSourceBlend.SelectedItem).Value;
        }

        private void tscbBlendOperation_SelectedIndexChanged(object sender, EventArgs e)
        {
            Device.RenderState.BlendOperation = (BlendOperation)((SimpleComboBoxItem)tscbBlendOperation.SelectedItem).Value;

        }

        private void tscbDestinationBlend_SelectedIndexChanged(object sender, EventArgs e)
        {
            Device.RenderState.DestinationBlend = (Blend)((SimpleComboBoxItem)tscbDestinationBlend.SelectedItem).Value;

        }

		private Vector3 defaultNewPosition = new Vector3(10, 0, 0);

		private void tsmiNewCartesian3dAxis_Click(object sender, EventArgs e)
		{
			Cartesian3dAxis theObject= new Cartesian3dAxis();
			//ObjectsEditor.ReloadList();
			//ObjectsEditor.Selected = theObject;
			//ObjectsEditor.OnlyForm.Show();
			AddObject(theObject);
		}

		private void tsmiNewCartesian3dFunction_Click(object sender, EventArgs e)
		{
			Cartesian3dFunction theObject = new Cartesian3dFunction(Device, mRenderer);
			//dont need to add or anything to a list... registered..done.
			//ObjectsEditor.ReloadList();
			//ObjectsEditor.Selected = theObject;
			//ObjectsEditor.OnlyForm.Show();
			AddObject(theObject);
		}

		private void tsmiNewCartesian3dSurface_Click(object sender, EventArgs e)
		{
			Cartesian3dSurface theObject = new Cartesian3dSurface(Device, mRenderer);
			//ObjectsEditor.ReloadList();
			//ObjectsEditor.Selected = theObject;
			//ObjectsEditor.OnlyForm.Show();
			AddObject(theObject);
		}

		private void tsmiNewDWave3d_Click(object sender, EventArgs e)
		{
			DWave3d theObject = new DWave3d(Device, mRenderer);
			AddObject(theObject);
		}

		private void tsmiNewFluid_Click(object sender, EventArgs e)
		{
			WaveEditor theObject = new WaveEditor(Device, mRenderer, this);
            theObject.Show();
			AddObject(theObject);
		}

		private Vector3 dAddVector = new Vector3(10,0,0);
		private void AddObject(object theObject)
		{
			ObjectsEditor.OnlyForm.AddUserObject(theObject);
			ObjectsEditor.ReloadList();

			//dont need to add or anything to a list... registered..done.
			if (theObject is IModelTransformable)
			{
				((IModelTransformable)theObject).ModelView.Position = defaultNewPosition;
				defaultNewPosition += dAddVector ;
				if (theObject is IManagedModelTransformable)
				{
					((IManagedModelTransformable)theObject).UpdateTransform();
				}
				ObjectsEditor.Selected = theObject;
				ObjectsEditor.OnlyForm.Show();
			}


			if (theObject.GetType().BaseType == typeof(Form))
			{
				Form theFormToAdd = (Form)theObject;
				theFormToAdd.Show();
				//PrimitivesEditor.OnlyForm.AddForm(theFormToAdd, false);
			}
		}
		private static bool ITypeFilter(Type t, Object obj)
		{
			string objectTypeString = obj.ToString();
			string typeTypeString = t.ToString();
			if (objectTypeString == typeTypeString)
				return true;
			else
				return false;
		}

		private bool ImplementsType(object o, Type t)
		{

			System.Reflection.TypeFilter filterRenderables = new System.Reflection.TypeFilter(ITypeFilter);
			Type[] iList = o.GetType().FindInterfaces(filterRenderables, t);
			if (iList.Contains(t))
				return true;
			else
				return false;
		}
		private void tsmiNewPolarWaveForm_Click(object sender, EventArgs e)
		{
			PolarWaveform theObject = new PolarWaveform();
			AddObject(theObject);
		}

		private void tsmiNewSimple3dRectangle_Click(object sender, EventArgs e)
		{
			Simple3dRectangle theObject = new Simple3dRectangle();
			AddObject(theObject);
		}

		private void tsmiNewSimple3dCircle_Click(object sender, EventArgs e)
		{
			Simple3dCircle theObject = new Simple3dCircle();
			AddObject(theObject);
		}

		private void tsmiNewTriangleFan_Click(object sender, EventArgs e)
		{
			TriangleFan theObject = new TriangleFan();
			AddObject(theObject);
		}

		private void tsmiNewAnimatedPW_Click(object sender, EventArgs e)
		{
			AnimatedPolarWaveform theObject = new AnimatedPolarWaveform();
			//dont need to add or anything to a list... registered..done.
			AddObject(theObject);
		}

		private void tsmiNewAnimated3dSurface_Click(object sender, EventArgs e)
		{
			AnimatedCartesian3dSurface theObject = new AnimatedCartesian3dSurface(Device, mRenderer);
			AddObject(theObject);
		}

		private void tstbBlendFactorBackColor_Click(object sender, EventArgs e)
		{
			cdBlendFactor.ShowDialog();
			tstbBlendFactorBackColor.BackColor = cdBlendFactor.Color;
			Device.RenderState.BlendFactor = cdBlendFactor.Color;

		}

		private void tsmiRenderStateEditor_Click(object sender, EventArgs e)
		{
			RenderStateViewer theEditor = new RenderStateViewer();
			AddObject(theEditor);
			theEditor.Show();
		}

		private void tsmiCameraDefault_Click(object sender, EventArgs e)
		{
			if (Camera.DefaultCamera != null)
			{
				Camera.DefaultCamera.Show();
			}

		}

		private void tsmiWindows_Click(object sender, EventArgs e)
		{
			tsmiCameraDefault.Text = String.Format(tsmiCameraDefault.Text, Camera.DefaultCamera.CameraNumber);

			object[] cameras = Camera.CameraForms.Cast<object>().ToArray<object>();
			if (cameras == null || cameras.Count() == 0)
				tscbCameraForms.Text = "<NONE - hint: create more with New.>";
			else
			{
				tscbCameraForms.Text = "All " + cameras.Count().ToString();
				tscbCameraForms.ComboBox.Items.Clear();
				tscbCameraForms.ComboBox.DisplayMember = "ObjectName";
				tscbCameraForms.ComboBox.Items.AddRange(cameras);
				tscbCameraForms.ComboBox.Update();
			}



			object[] userCreatedForms = (from object o in ObjectsEditor.UserObjectsList where o.GetType().BaseType == typeof(Form) select o).ToArray<object>();
			object[] formsWithNamed = (from object f in userCreatedForms where f is INamed select f).ToArray<object>(); //I dont do this alot but this is my linq query.
			if (formsWithNamed == null || formsWithNamed.Length == 0)
			{
				tscbOtherForms.Text = "<None>";
			}
			{
				int formsNotNamedCount = userCreatedForms.Length - formsWithNamed.Length;
				tscbOtherForms.Text = "All " + formsWithNamed.Length.ToString()
					+ (formsNotNamedCount == 0 ? "" : " (" + formsNotNamedCount.ToString() + " hidden)") ;
				tscbOtherForms.ComboBox.Items.Clear();
				tscbOtherForms.ComboBox.DisplayMember = "ObjectName";
				tscbOtherForms.ComboBox.Items.AddRange(formsWithNamed);
				tscbOtherForms.ComboBox.Update();
			}
		}


	   	private void DirectXForm_KeyDown(object sender, KeyEventArgs e)
		{
            if (e.KeyCode == Keys.Space)
            {
                mnuMain.Visible = !mnuMain.Visible;
            }
			if (e.KeyCode == Keys.Tab)
			{
				//select next rangeable (if any) into the selectmesh
				SelectNextRangable();
			}
			if (e.KeyCode == Keys.A)
			{
				//switch (Device.RenderState.AmbientMaterialSource)
				//{
				//    case ColorSource.Color1:
				//        Device.RenderState.AmbientMaterialSource = ColorSource.Material;
				//        mMainProgram.OutputForm.OutputThenGoAway("RenderState.AmbientMaterialSource = Material");
				//        break;
				//    case ColorSource.Material:
				//        Device.RenderState.AmbientMaterialSource = ColorSource.Color1;
				//        mMainProgram.OutputForm.OutputThenGoAway("RenderState.AmbientMaterialSource = Color1");
				//        break;
				//}
			}
			else if (e.KeyCode == Keys.D)
			{
				//switch (Device.RenderState.DiffuseMaterialSource)
				//{
				//    case ColorSource.Color1:
				//        Device.RenderState.DiffuseMaterialSource = ColorSource.Material;
				//        mMainProgram.OutputForm.OutputThenGoAway("RenderState.DiffuseMaterialSource = Material");
				//        break;
				//    case ColorSource.Material:
				//        Device.RenderState.DiffuseMaterialSource = ColorSource.Color1;
				//        mMainProgram.OutputForm.OutputThenGoAway("RenderState.DiffuseMaterialSource = Color1");
				//        break;
				//}
				if (Camera.DefaultCamera!=null)
					Camera.DefaultCamera.Show();
			}
			else if (e.KeyCode == Keys.E)
			{
				ObjectsEditor.OnlyForm.Show();//preferred way to reference the only form.
			}
			else if (e.KeyCode == Keys.F)
			{
				if (Device.RenderState.FillMode == FillMode.WireFrame)
					Device.RenderState.FillMode = FillMode.Solid;
				else if (Device.RenderState.FillMode == FillMode.Solid)
					Device.RenderState.FillMode = FillMode.Point;
				else if (Device.RenderState.FillMode == FillMode.Point)
					Device.RenderState.FillMode = FillMode.WireFrame;
			}
			else if (e.KeyCode == Keys.S)
			{
				//switch (Device.RenderState.SpecularMaterialSource)
				//{
				//    case ColorSource.Color1:
				//        Device.RenderState.SpecularMaterialSource = ColorSource.Material;
				//        mMainProgram.OutputForm.OutputThenGoAway("RenderState.SpecularMaterialSource = Material");
				//        break;
				//    case ColorSource.Material:
				//        Device.RenderState.SpecularMaterialSource = ColorSource.Color1;
				//        mMainProgram.OutputForm.OutputThenGoAway("RenderState.SpecularMaterialSource = Color1");
				//        break;
				//}
			}

			else if (e.KeyCode == Keys.L)
			{
				//if (mMainProgram.AlphaBlendingType == 4)
				//{
				//    mMainProgram.AlphaBlendingType = 0;
				//}
				//else
				//{
				//    mMainProgram.AlphaBlendingType += 1;
				//}
				//mMainProgram.OutputForm.OutputThenGoAway("Alpha blending type: " + mMainProgram.AlphaBlendingType.ToString());

				mMainProgram.LightingForm.Show();//use main program to get default and only lighting form... possible revision.
			}
			else if (e.KeyCode == Keys.M)
			{
				Mouse.OnlyMouse.Show();
			}
			else if (e.KeyCode == Keys.O)
			{
				OutputForm.PrimaryOutputForm.Show(); 
			}
			else if (e.KeyCode == Keys.P)
			{
				this.tsmiNewPrimitive.ShowDropDown();
			}
			else if (e.KeyCode == Keys.R)
			{
				RenderStateViewer.OnlyForm.Show();
			}
			else if (e.KeyCode == Keys.W)
			{
				this.tsmiWindows.ShowDropDown();
			}

			//else if (epsilon.KeyCode == Keys.V)
			//{
			//    FOV_Y_halfPiDivisor++;
			//    if (FOV_Y_halfPiDivisor == 10)
			//        FOV_Y_halfPiDivisor = 1;

			//    mMainProgram.SetupTransformProjection(FOV_Y_halfPiDivisor);
			//    mMainProgram.OutputForm.OutputThenGoAway("Transform Projection with FOV_Y_HalfPiDivisor = " + FOV_Y_halfPiDivisor);
			//}


		}

		private void SelectNextRangable()
		{
			//from the primitives that are rangeable, 
			object[] all = ObjectsEditor.GetCurrentViewableList();
			
			if (all == null || all.Length == 0 || SelectMesh.OnlyObject == null)
				return;
			//in addition to selecting all rangeables, make sure also that we exclude the select mesh object itself which is also Rangeable.
			IRangeModifiable[] allRangeable = (from object o in all where o is IRangeModifiable && !(o==SelectMesh.OnlyObject) select o as IRangeModifiable).ToArray<IRangeModifiable>();

			IRangeModifiable nextR = null;
			
			IRangeModifiable selected = SelectMesh.OnlyObject.Selected as IRangeModifiable;
			if (selected == null || (allRangeable[allRangeable.Length - 1] == selected))//if null or selected is last, move to first
				nextR = allRangeable[0];//select first
			else
			{
				//start from selected rangeable and go to next
				//int idxOfSelected = allRangeable.First<IRangeableOld>(delegate bool (IRangeableOld) { 
				for (int i = 0; i < allRangeable.Length; i++)
				{
					if (selected == allRangeable[i]) 
					{
						nextR = allRangeable[i + 1];
						break;
					}
				}
			}					 
			//now that we finally have the next Rangeable to select, do indeed select it into the mesh
			SelectMesh.OnlyObject.Selected = nextR;
			SelectMesh.OnlyObject.Visible = true;
			SelectMesh.OnlyObject.Recreate();

		}

		private void tsmiMouseWindow_Click(object sender, EventArgs e)
		{
			Mouse.OnlyMouse.Show();
		}

		private void tscbOtherForms_SelectedIndexChanged(object sender, EventArgs e)
		{
			((Form)tscbOtherForms.SelectedItem).Show();
		}

		private void tscbCameraForms_SelectedIndexChanged(object sender, EventArgs e)
		{
			((Form)tscbCameraForms.SelectedItem).Show();
		}

		private void tsmiNew3dTextMesh_Click(object sender, EventArgs e)
		{
			bool createVisible = true;
			FontMesh theObject = new FontMesh(createVisible);
			AddObject(theObject);
		}

	}

	public class ComboBoxEnumList
	{
		object[] enumArray;
		ComboBox control;

		public ComboBox Control
		{
			get { return control; }
			set { control = value; }
		}
		public void Select(int selectedValue)
		{
			for (int idx = 0; idx <= enumArray.Length; idx++)
			{
				if (((SimpleComboBoxItem)enumArray[idx]).Value == selectedValue)
				{
					control.SelectedIndex = idx;
					break;
				}
			}
		}

		public void Fill(ToolStripComboBox tscb, int selectedValue)
		{
			Fill(tscb.ComboBox, selectedValue);
		}
		public void Fill(ComboBox cboControl, int selectedValue)
		{
			control = cboControl;

			cboControl.Items.AddRange(enumArray);
			cboControl.ValueMember= "Value";
			cboControl.DisplayMember = "Text";

			Select(selectedValue);
			cboControl.Update();
		}
		public ComboBoxEnumList(Type enumerationType)
		{
			Array values = Enum.GetValues(enumerationType);
			string[] names = Enum.GetNames(enumerationType);

			enumArray = new SimpleComboBoxItem[values.Length];
			for(int idx = 0; idx < values.Length; idx++)
			{
				SimpleComboBoxItem cbi = new SimpleComboBoxItem((int)values.GetValue(idx), (string)names[idx]);
				enumArray[idx] = cbi;
			}
		}
	}

	public class SimpleComboBoxItem
	{
		public SimpleComboBoxItem(int selectedValue, string displayText)
		{
			value = (int)selectedValue;
			text = displayText;
		}
		private int value;

		public int Value
		{
			get { return this.value; }
			set { this.value = value; }
		}
		private string text;

		public string Text
		{
			get { return text; }
			set { text = value; }
		}
	}
}	
